/**
 * Project Name:api-webhook
 * File Name:EmailClient.java
 * Package Name:com.example.service.webhook.api
 * Date:2016年7月19日下午5:17:42
 * Copyright (c) 2016, yuandong@51dojo.com All Rights Reserved.
 */

package com.example.service.webhook.business.chsi.api;

import com.example.service.webhook.api.MoxieClient;
import com.example.service.webhook.business.chsi.dto.AllData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;

/**
 * ClassName:ChsiClient <br/>  
 * Function: 学信网client. <br/>  
 * Reason:   TODO ADD REASON. <br/>  
 * Date:     2016年7月19日 下午5:17:42 <br/>  
 * @author yuandong
 * @version
 * @since JDK 1.6
 * @see
 */
@Component
public class ChsiClient extends MoxieClient {

    private ChsiApi api;

    @Autowired
    public ChsiClient(@Value("${moxie.api.baseUrl}") String apiBaseUrl,
                      @Value("${moxie.api.token}") String apiToken) {
        super(apiBaseUrl, apiToken);
        api = retrofit.create(ChsiApi.class);
    }

    private static final Logger LOGGER = LoggerFactory.getLogger(ChsiClient.class);


/*    public EducationInfoDetail getEducation(String taskId) throws IOException {
        Call<EducationInfoDetail> call = api.getEducation(taskId);
        Response<EducationInfoDetail> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getEducation, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }

    public StudentInfoDetail getStudent(String taskId) throws IOException {
        Call<StudentInfoDetail> call = api.getStudent(taskId);
        Response<StudentInfoDetail> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getStudent, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }*/

    public AllData getAllData(String taskId) throws IOException {
        Call<AllData> call = api.getAllData(taskId);
        Response<AllData> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getAllData, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }

}
  
